function [image,imageSize]=loadModis1BData(fname)
% loadModisData         - read Modis 1B image 
%
%  Reads an image of Modis 1B hdf type 
%  to a [col x line x band] MATLAB array
% image=loadModis1BData(fname)
% [image,imageSize]=loadModis1BData(fname)
%
% INPUT :
%
% fname string giving the full pathname of the Modis 1B image to read.
%
% OUTPUT :
%
% image----------- c by l by b array containing the Modis 1B image values organised in
%    c : cols, l : lines and b : bands.
% imageSize         the [3,1]  size matrix of the image
% imageSize(1): the number of columns; imageSize(2): the number of lines;
% imageSize(3): the number of bands
%
%
%%%%%%%%%%%%%

% Check user input
if ~ischar(fname)
   error('fname should be a char string');
end
    
sd_id = hdfsd('start',fname,'read');

% find the information
[ndatasets,nglobal_attr,status] = hdfsd('fileinfo',sd_id);
% HDF4 file contains ndatasets data sets and nglobal_attr global attribute.
% vaule=-1 denotes unsuccessful
if (status== -1)
   error('Modis data does not exist')
end
       
% get an file attibutes
fileinfo=hdfinfo(fname);
data=cell(32,1);
ds_name=cell(32,1);
for i=0:ndatasets-1
     sds_id = hdfsd('select',sd_id,i);
     [ds_name{i+1}, ds_ndims, ds_dims, ds_type, ds_atts, stat]=...
     hdfsd('getinfo',sds_id);
     ds_start = zeros(1,ds_ndims); % Creates the vector [0 0]
     ds_stride = [];
     ds_edges = ds_dims;
     [data{i+1},status]=hdfsd('readdata',sds_id,ds_start,ds_stride,ds_edges);
     if (status== -1)
        error('error in loading Modis Data')
     end
end

% combine the image of different bands
p=size(data{10});
p(3)=38;
image=zeros(p(1),p(2),p(3));
image(:,:,1:2)=data{7};
image(:,:,3:7)=data{10};
image(:,:,8:21)=data{3}(:,:,1:14);
image(:,:,22:27)=data{5}(:,:,1:6);
image(:,:,28)=data{3}(:,:,15);
image(:,:,29:38)=data{5}(:,:,7:16);
imageSize=p;
    
